/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

/**
 *
 * @author alocubiche
 */
import java.sql.*;

public class MySQLManager{
  private static Connection conn = null;
  
  public static Connection getConnection(){ return conn;}
  
  public static boolean connect() 
  {
    boolean success = false;
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "tp_ecommerce";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "root"; 
    String password = "";
    try {
        Class.forName(driver).newInstance();
        conn = DriverManager.getConnection(url+dbName,userName,password);
        System.out.println("Connected to the database");
        success=true;
    } catch (Exception e) {
        System.out.println("Erreur lors de la connexion");
        e.printStackTrace();
    }
    return success;
  }
  public static boolean disconnect()
  {
    boolean success = false;
    try {
        conn.close();
        System.out.println("Disconnected from database");
        success=true;
    } catch(Exception e) {
        System.out.println("Erreur lors de la déconnexion");
        e.printStackTrace();
    }
    return success;
  }
}